package com.shujia.flink.transformation

import java.{lang, util}

import org.apache.flink.streaming.api.collector.selector.OutputSelector
import org.apache.flink.streaming.api.scala._

object Demo7Split {
  def main(args: Array[String]): Unit = {


    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    val ds1: DataStream[String] = env.socketTextStream("master", 9999)

    /**
      * 闯入学生表的数据
      *
      * 将男和女的学生分成两个流
      *
      */

    val splitDS: SplitStream[String] = ds1.split(new OutputSelector[String] {
      override def select(value: String): lang.Iterable[String] = {
        val sex: String = value.split(",")(3)

        if (sex.equals("男")) {
          val list: util.ArrayList[String] = new util.ArrayList[String]()
          list.add("男")
          list
        } else {
          val list: util.ArrayList[String] = new util.ArrayList[String]()
          list.add("女")
          list
        }
      }
    })


    val nanDS: DataStream[String] = splitDS.select("男")

    val nvDS: DataStream[String] = splitDS.select("女")


    nvDS.print()

    env.execute()

  }
}
